package com.xzp.bams.utils;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @TODO
 * @Author xu
 * 2025/4/8
 */
public class ThreadPool {
    private ThreadPoolExecutor pool;

    /**
     * 创建线程池
     * @param maxPoolSize  池子中允许最大的线程数量
     * @param queueSize    阻塞队列中允许的线程数
     * 自定义线程池，执行的最多任务数 = maxPoolSize + queueSize
     */
    public ThreadPool(int maxPoolSize , int queueSize){
        pool = new ThreadPoolExecutor(5, maxPoolSize ,
                60 , TimeUnit.SECONDS , new LinkedBlockingQueue<>(queueSize));
    }

    //执行方法
    public void execute(Runnable runnable){
        pool.submit(runnable);
    }


}
